if (typeof Quibbox == "undefined") var Quibbox = {};

Quibbox.RPC = {
	call: function (f, data, options)
	{
		if (!options) options = {};
		
		console.info("             [client.rpc] Calling '%s', data: %o", f, data);
		
		successCallback = options.success;
		errorCallback = options.error;
		
		options.dataType = "json";
		options.url = 'rpc/?f='+f;
		options.cache = false;
		options.data = data;
		
		options.success = function (data, textStatus) {
			if (data.console) eval(data.console);
			
			if (data.success) {
				console.info("             [client.rpc] AJAX RPC call '%s' successful, result: %o", f, data);
				if (typeof successCallback == "function") successCallback(data);
			} else {
				if (typeof errorCallback == "function") errorCallback();
			}
		};
		options.error = function (XMLHttpRequest, textStatus, errorThrown) {
			console.error(textStatus);
			if (typeof errorCallback == "function") errorCallback();
		};
		
		$.ajax(options);
	}
}